//==================================================================
//  Copyright (C) 2006-2007  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
///
//==================================================================

#ifndef GADGET_MANAGER_H
#define GADGET_MANAGER_H

#include "psys.h"
#include "psys_stdgfx.h"
#include "pwindow.h"
#include "guibase.h"

//==================================================================
class GGET_Manager
{
	std::vector<GGET_Item *>	_items;
	GGET_Callback		_cback;
	void				*_cback_userdatap;
public:
	GuiBaseManager		_base_manager;

public:
	GGET_Manager() :
		_cback(NULL),
		_cback_userdatap(NULL)
	{
	}

	~GGET_Manager()	// implicitly deletes items
	{
		for (int i=0; i < _items.size(); ++i)
			delete _items[i];
	}


	GGET_EditBox	*AddEditBox( int gget_id, int x, int y, int w, int h, const TCHAR *txtp );
	GGET_Button		*AddButton( int gget_id, int x, int y, int w, int h, const TCHAR *titlep );
	GGET_Tab		*AddTab( int gget_id, int x, int y, int w, int h, const TCHAR *titlep );
	GGET_StaticText *AddStaticText( int gget_id, int x, int y, int w, int h, const TCHAR *txtp );

	void			RemoveItem( int gget_id );

	void			EnableGadget( int gget_id, bool onoff );
	void			SetToggleType( int gget_id, bool onoff );
	void			SetGadgetText( int gget_id, const TCHAR *txtp );

	void			SetToggled( int gget_id, bool onoff );
	bool			GetToggled( int gget_id );

	GGET_Item		*FindGadget( int gget_id );
	void			ChangeGadgetID( int old_gget_id, int new_gget_id );

	static int		EventFilter_s( void *userdatap, WindowEvent *eventp );
	int				EventFilter( WindowEvent *eventp );

	void			SetCallback( GGET_Callback cback, void *cback_userdatap )
					{
						_cback = cback;
						_cback_userdatap = cback_userdatap;
					}

private:
	void			OnPaint( class WindowEvent *eventp );
	void			ActivateOne( GGET_Item *activatep );
	void			setGadgetFlags( int gget_id, u_int mask, bool onoff );
	bool			getGadgetFlags( int gget_id, u_int mask );
};



#endif
